package com.tcc.qa.test.util;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

public class DatePicker {
	public static WebDriver getDatePicker(WebDriver driver){
		  driver.findElement(By.cssSelector("img.cc16")).click();
		  return driver;
	}
  public static WebDriver selectToday(WebDriver driver) {
     driver.findElement(By.cssSelector("img.cc16")).click();
     driver.switchTo().frame(driver.findElement(By.id("datePicker")));
     driver.findElement(By.xpath("html/body/form/table/tbody/tr[2]/td/div/table/tbody/tr/td[3]/a")).click(); //select today
     driver.switchTo().defaultContent(); 
     return driver;
  }
  public static WebDriver selectPreDay(WebDriver driver) {
	     driver.findElement(By.cssSelector("img.cc16")).click();
	     driver.switchTo().frame(driver.findElement(By.id("datePicker")));
	     driver.findElement(By.xpath("//body/form/table/tbody/tr[2]/td/div/table/tbody/tr/td[2]/a/img")).click();	
			driver.findElement(By.xpath("//table[@id='ccCalTable']/tbody/tr[2]/td[2]/a")).click();    //select previous day
			driver.switchTo().defaultContent(); 
	     return driver;
	  }
  public static WebDriver selectLaterDay(WebDriver driver,int month) {
	     driver.findElement(By.cssSelector("img.cc16")).click();
	     driver.switchTo().frame(driver.findElement(By.id("datePicker")));
	     new Select(driver.findElement(By.xpath("html/body/form/table/tbody/tr[1]/td[1]/select"))).selectByIndex(month-1);//by select
			driver.findElement(
					By.xpath("//table[@id='ccCalTable']/tbody/tr[2]/td[3]/a")).click();
			driver.switchTo().defaultContent();  
	     return driver;
	  }
}
